<!DOCTYPE html>
<!-- 管理学生 -->
<html>
<head>
    <meta charset="utf-8">
    <title>信息修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <link rel="stylesheet" href="../css/modifyData.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->


</head>
<body>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>信息修改</legend>
</fieldset>
<div class="layui-row updatedata ">
    <form class="layui-form ">
        <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->

        <div class="layui-form-item">
            <div class="layui-input-block" style="width: 200px;">
                <a class="upimg" title="我的头像">
                    <img src=".././images/avatar.png" class="userAvatar">
                </a>
            </div>
        </div>
        <br>
        <div class="layui-form-item" style="left:">
            <label class="layui-form-label">账号：</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="userid" id="userid" autocomplete="off"
                       class="layui-input" readonly="readonly" value="AAAAA">
            </div>
        </div>

        <div class="layui-form-item" style="left:">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="realName" id="realName" autocomplete="off"
                       class="layui-input" value="AAAAA">
            </div>
        </div>


        <div class="layui-form-item" style="left:">
            <label class="layui-form-label">所属类型：</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="type" id="type" autocomplete="off"
                       class="layui-input" readonly="readonly" value="超级管理员">
            </div>
        </div>

        <div class="layui-form-item" style="left:">
            <label class="layui-form-label">联系电话：</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="phone" id="phone" autocomplete="off"
                       class="layui-input" placeholder="请输入联系电话">
            </div>
        </div>


        <br>
        <br>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="updataModify">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" style="margin-left: 80px;">重置</button>
            </div>
        </div>
        <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
    </form>
</div>


<script src="../lib/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(["form", "okGVerify", "okUtils", "okLayer",], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let okGVerify = layui.okGVerify;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();


        // 获取user 账户
        var user = JSON.parse(window.sessionStorage.getItem("user"));

        console.log(user)
        //判断登录类型 调用修改方法
        if (user.type == null) {
            var freshwork = setInterval(freshstatusInstructot, 600000);
            freshstatusInstructot();
            //    var userdata={
            // 	instructorid:,

            //    }
        } else {
            var freshwork = setInterval(freshstatusAdmin, 600000);
            freshstatusAdmin();

        }

        //定时循环刷新状态
        //admin
        function freshstatusAdmin() {

            $.ajax({
                url: ctx + "/admin/getadminByid",
                type: "GET",
                data: {adminid: user.adminid},
                dataType: "JSON"
            }).done(function (response) {
                if (response.code == 200) {
                    window.sessionStorage.setItem("user", JSON.stringify(response.data));
                    var en = response.data;

                    $("#userid").val(en.adminid);
                    $("#realName").val(en.realname);
                    if (en.type > 10) {
                        $("#type").val("超级管理员");
                    } else {
                        $("#type").val("普通管理员");
                    }

                    $("#phone").val(en.contactnumber);

                }
            }).fail(function () {
                parent.location.href = "adminLogin.html";
            })
        }

        //辅导员
        function freshstatusInstructot() {

            $.ajax({
                url: ctx + "/admin/getinstructorByid",
                type: "GET",
                data: {instructorid: user.instructorid},
                dataType: "JSON"
            }).done(function (response) {
                if (response.code == 200) {
                    window.sessionStorage.setItem("user", JSON.stringify(response.data));
                    var en = response.data;
                    $("#userid").val(en.instructorid)
                    $("#realName").val(en.counselorsname)
                    $("#type").val("辅导员")
                    $("#phone").val("")
                }
            }).fail(function () {
                parent.location.href = "instuctorLogin.html";
            })
        }

        form.on("submit(updataModify)", function (data) {
            if (user.type != null) {
                alert("开始")
                var userdata = {
                    adminid: user.adminid,
                    realname: $('#realName').val(),
                    contactnumber: $('#phone').val(),
                }

                okUtils.ajax("/admin/updateadmin", "post", userdata, true).done(function (response) {
                    window.sessionStorage.setItem("user", JSON.stringify(response.data));
                    okLayer.greenLaughMsg(response.msg, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload(); //刷新父页面
                        parent.layer.close(index);

                    })
                }).fail(function (error) {
                    console.log(error)
                });
            } else {
                var userdata = {
                    instructorid: user.instructorid,
                    counselorsname: $('#realName').val(),
                    //contactnumber:$('#phone').val(),
                }
                okUtils.ajax("/admin/updateInstructor", "post", userdata, true).done(function (response) {
                    window.sessionStorage.setItem("user", JSON.stringify(response.data));
                    okLayer.greenLaughMsg(response.msg, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload(); //刷新父页面
                        parent.layer.close(index);

                    })
                }).fail(function (error) {
                    console.log(error)
                });
            }
            return false;
        });
    });
</script>

</body>
</html>